package com.cy.sdk.sms;

import java.io.Serializable;

/**
 * Created by Dio-Nbook on 13-12-26.
 */
public class SMSValidCode implements Serializable{
    public static final String CACHE_CODE = "se.reg.valid";
    String mobile;
    String validCode;
    long sendTime;

    /**
     * 下一次发送间隔
     */
    final static long MARGIN_SEND_MS = 1000 * 60;

    /**
     * 失效市场  5分钟
     */
    final static long INVALID_TIME_MS = 1000 * 60 * 5;

    /**
     * 判断是否可以进行下一次发送
     *
     * @return true 可发送 false 不可发送
     */
    public boolean nextSend() {
        if ((System.currentTimeMillis() - sendTime) > MARGIN_SEND_MS) {
            return true;
        }
        return false;
    }

    public boolean valid(String validCode) {
        if ((System.currentTimeMillis() - sendTime) > INVALID_TIME_MS) {
            return false;
        }
        return this.validCode.equals(validCode);
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getValidCode() {
        return validCode;
    }

    public void setValidCode(String validCode) {
        this.validCode = validCode;
    }

    public long getSendTime() {
        return sendTime;
    }

    public void setSendTime(long sendTime) {
        this.sendTime = sendTime;
    }
}
